package com.ybkj.o2o.mc.controller.res;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ybkj.o2o.mc.common.transport.Result;
import com.ybkj.o2o.mc.entity.PassengerManage;
import com.ybkj.o2o.mc.manager.PassengerManageManager;
import com.google.common.base.Preconditions;
import com.google.gson.Gson;

/**
 * Created by shine on 15/8/25.
 */
@RestController
@RequestMapping(value = "api/passengerManagers")
public class PassengerManagerRes {

	@Autowired
	private PassengerManageManager passengerManageManager;
	
	/**
	 * 通过参数查询单个管理员.
	 */
	@RequestMapping(value = { "", "/" }, method = RequestMethod.GET)
	public ResponseEntity<Object> findPassengerManagerByParam(
			@RequestParam(required = false, value = "id") Long id,
			@RequestParam(required = false, value = "manageAccount") String manageAccount,
			@RequestParam(required = false, value = "managePassword") String managePassword,
			@RequestParam(required = false, value = "manageGrade") Integer manageGrade,
			@RequestParam(required = false, value = "enterpriseId") Long enterpriseId,
			@RequestParam(required = false, value = "enterpriseName") String enterpriseName,
			@RequestParam(required = false, value = "departmentId") Long departmentId,
			@RequestParam(required = false, value = "departmentName") String departmentName,
			@RequestParam("appKey") String appKey) {

		ResponseEntity<Object> responseEntity = null;

		appKey = StringUtils.trimToEmpty(appKey);
		Preconditions.checkArgument(StringUtils.isNotBlank(appKey),
				"AppKey不能为空");
		
		PassengerManage passengerManage = new PassengerManage();
		passengerManage.setAppKey(appKey);
		passengerManage.setDepartmentId(departmentId);
		passengerManage.setDepartmentName(departmentName);
		passengerManage.setEnterpriseId(enterpriseId);
		passengerManage.setEnterpriseName(enterpriseName);
		passengerManage.setManageAccount(manageAccount);
		passengerManage.setManagePassword(managePassword);
		passengerManage.setManageGrade(manageGrade);
		
		Gson gson = new Gson();
		
		passengerManage = passengerManageManager.findPassengerManagerByParam(passengerManage);
		
		Result<PassengerManage> result = new Result<>(0, "成功", passengerManage);

		responseEntity = new ResponseEntity<>(result, HttpStatus.OK);

		return responseEntity;
		
		
	}
}
